package com.socialrss.adapters;

import java.util.ArrayList;

import com.socialrss.R;
import com.socialrss.viewlisteners.MainActivity;

import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

public class SpAdapter implements SpinnerAdapter{

    /**
     * The internal data (the ArrayList with the Objects).
     */
    private static ArrayList<String> data;
    private Context cont;
    private static ArrayList<Integer> groupId;
    public SpAdapter(ArrayList<String> data, Context cont, ArrayList<Integer> groupId){
    	super();
        this.data = data;
        this.cont = cont;
        this.groupId = groupId;
    }

    /**
     * Returns the Size of the ArrayList
     */
    @Override
    public int getCount() {
        return data.size();
    }

    /**
     * Returns one Element of the ArrayList
     * at the specified position.
     */
    @Override
    public Object getItem(int position) {
        return data.get(position);
    }
    
    public int getItemGroupId(int position) {
        return groupId.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {
        return android.R.layout.simple_spinner_dropdown_item;
    }

    /**
     * Returns the View that is shown when a element was
     * selected.
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView v = new TextView(cont);
        v.setGravity(Gravity.RIGHT);
        v.setTextColor(Color.BLACK);
        v.setText(data.get(position));
        return v;
    }

    @Override
    public int getViewTypeCount() {
        return 1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isEmpty() {
        return false;
    }

    @Override
    public void registerDataSetObserver(DataSetObserver observer) {
        // TODO Auto-generated method stub

    }

    @Override
    public void unregisterDataSetObserver(DataSetObserver observer) {
        // TODO Auto-generated method stub

    }

    /**
     * The Views which are shown in when the arrow is clicked
     * (In this case, I used the same as for the "getView"-method.
     */
    @Override
    public View getDropDownView(int position, View convertView,
            ViewGroup parent) {
        return this.getView(position, convertView, parent);
    }

}